Skip to content

type-c-service: Migrate to async function calls#833

Open
RobertZ2011 wants to merge 9 commits into
OpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-service-direct-async-calls
Open

type-c-service: Migrate to async function calls#833
RobertZ2011 wants to merge 9 commits into
OpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-service-direct-async-calls

Conversation

@RobertZ2011
Copy link
Copy Markdown
Contributor

@RobertZ2011 RobertZ2011 commented May 6, 2026

  • Remove bridge code and last bit of messaging
  • Final move away from Context type, application code is now responsible for creating event senders/receivers
  • Remove almost all GlobalPortId usage

@RobertZ2011 RobertZ2011 self-assigned this May 6, 2026
@RobertZ2011 RobertZ2011 force-pushed the type-c-service-direct-async-calls branch from 0e41390 to 39cc831 Compare May 7, 2026 18:10
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Cargo Vet Audit Passed

cargo vet has passed in this PR. No new unvetted dependencies were found.

@github-actions github-actions Bot added the cargo vet PRs pending auditor review label May 7, 2026
@RobertZ2011 RobertZ2011 force-pushed the type-c-service-direct-async-calls branch 2 times, most recently from de3f1b1 to 352e330 Compare May 7, 2026 22:02
Transitioning away from the last bit of messaging code, no longer
needed.
@RobertZ2011 RobertZ2011 force-pushed the type-c-service-direct-async-calls branch from 6e6e4b4 to a4c73a2 Compare May 13, 2026 20:18
@RobertZ2011 RobertZ2011 requested review from Copilot May 13, 2026 20:20
@RobertZ2011 RobertZ2011 changed the title Type c service direct async calls type-c-service: Migrate to async function calls May 13, 2026
@RobertZ2011 RobertZ2011 force-pushed the type-c-service-direct-async-calls branch from a4c73a2 to dd967cd Compare May 13, 2026 20:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Type-C service from a centralized Context + Bridge-based messaging architecture to direct async method calls on locked port objects. The Type-C service now operates over a generic Registration trait that exposes ports as &[&Port] and uses per-port event channels plus a new event receiver abstraction.

Changes:

  • Delete the bridge module and the service::context::Context request/response indirection; the service now calls Pd/UcsiLpm trait methods directly on locked ports.
  • Introduce service::registration::{Registration, ArrayRegistration} and service::event_receiver::ArrayEventReceiver; require port traits (Pd, Retimer, Controller, Lpm, SystemPowerStateStatus) to be Named.
  • Carry a port reference (&'port Port) in PortEvent/Event instead of GlobalPortId, and split Event from EventData.

Reviewed changes

Copilot reviewed 41 out of 44 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
type-c-service/src/service/mod.rs Replaces Context/cached port_status state with generic Registration; rewrites event types around port references
type-c-service/src/service/ucsi.rs UCSI processing now operates on locked port refs; reorganized state fields
type-c-service/src/service/power.rs Iterates over registration.ports() instead of using context; updates power policy event variant pattern
type-c-service/src/service/registration.rs New Registration trait + ArrayRegistration implementation
type-c-service/src/service/event_receiver.rs New ArrayEventReceiver / ArrayPortReceivers replacing old EventReceiver
type-c-service/src/service/vdm.rs File removed (VDM helpers no longer routed through service)
type-c-service/src/task.rs task is now generic over registration and the new event receiver
type-c-service/src/controller/*.rs Port struct gains a TypeCSender, removes global_port/context; all trait impls updated
type-c-service/src/controller/macros.rs Macro adds a Type-C event channel; create signature drops global port id and context
type-c-service/src/bridge/*.rs Bridge module deleted
type-c-service/src/lib.rs Remove pub mod bridge
type-c-interface/src/service/context.rs Context module removed
type-c-interface/src/service/event.rs PortEvent/Event now carry &'port Port; split into Event + EventData
type-c-interface/src/service/mod.rs Drops pub mod context
type-c-interface/src/port/{pd,retimer,power}.rs Traits require Named supertrait
type-c-interface/src/port/mod.rs Drops Command/Response/Device types (no longer needed without bridge)
type-c-interface/src/port/event.rs Adjust imports after port::mod slimming
type-c-interface/src/controller/{mod,pd,power,retimer}.rs Traits require Named supertrait
type-c-interface/src/ucsi.rs Lpm trait requires Named
type-c-interface/Cargo.toml Drops embassy-sync/embassy-time deps no longer needed
examples/std/src/lib/type_c/mock_controller.rs Adds name field and Named impl; Port type gains TypeCSender param
examples/std/src/bin/type_c/{service,ucsi,unconstrained}.rs Update to new registration/event-receiver wiring; remove bridge tasks
examples/std/src/bin/type_c/basic.rs Example removed
examples/std/Cargo.toml Drops the type-c-basic binary
examples/rt685s-evk/src/bin/{type_c,type_c_cfu}.rs Update example wiring; remove bridge task; second port now uses LocalPortId(1)
Cargo.lock / examples/*/Cargo.lock Lockfile updates

Comment thread type-c-service/src/service/ucsi.rs Outdated
Comment thread examples/rt685s-evk/src/bin/type_c.rs Outdated
Comment thread examples/rt685s-evk/src/bin/type_c_cfu.rs Outdated
Comment thread examples/std/src/bin/type_c/service.rs Outdated
Comment thread examples/std/src/bin/type_c/ucsi.rs Outdated
Comment thread examples/std/src/bin/type_c/unconstrained.rs Outdated
Continue moving away from context type. Application code must now setup
communication channels between port code and the type-C service.
Any device should have a human readable name.
Remove most uses of this type, limited it mostly to the UCSI code. Service
events now deal directly with referencs to port objects. Remove port
state stored in service implementation.
@RobertZ2011 RobertZ2011 force-pushed the type-c-service-direct-async-calls branch from dd967cd to 42ce430 Compare May 13, 2026 20:26
@RobertZ2011 RobertZ2011 marked this pull request as ready for review May 13, 2026 20:44
@RobertZ2011 RobertZ2011 requested review from a team as code owners May 13, 2026 20:44

/// Process a UCSI command
pub async fn process_ucsi_command(&mut self, command: &GlobalCommand) -> UcsiResponse {
pub async fn process_ucsi_command(&mut self, port: &'port Reg::Port, command: &GlobalCommand) -> UcsiResponse {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the client call this? Is the assumption that command will always be for the port passing in? Like the GlobalPortId within GlobalCommand will match the port referece passed in?

for port in self.registration.ports().iter() {
port.lock()
.await
.set_unconstrained_power(ptr::eq(*port, unconstrained_port))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic seems to have inverted from the previous behavior:

  • If it is the unconstrained port, then it is true, so it is unconstrained.
  • If it is not the unconstrained port, then it is false, so it is constrained

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cargo vet PRs pending auditor review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants